<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://unpkg.com/vue"></script>
    <script>
        window.onload=function(){
            var app4 = new Vue({
                el: '#app-4',
                methods: {
                    reverseMessage: function () {
                        this.username =''
                        this.age=''
                    },
                    addpeople:function(){
                        this.todos.push({name:this.username,age:this.age,time:new Date()});
                    },
                    scsy:function(){
                        this.todos={};
                    },
                    sc:function(index){
                        this.todos.splice(index,1);
                    }
                },
                data: {
                    name:'用户名',
                    nl:'年龄',
                    username:'',
                    age:'',
                    todos: [
                       { name:'hh',age:'21',time:new Date()},
                      { name:'wwb',age:'22' ,time:new Date()},
                       { name:'ljf',age:'21',time:new Date()}
                    ]
                },
                filters: {
                    capitalize: function (value) {
                        if (!value) return ''
                        value = value.toString()
                        return value.charAt(0).toUpperCase() + value.slice(1)
                    }
                }
            })
        }
    </script>
</head>
<body>

<div id="app-4">

    <p>{{name}}</p>
    <input v-model="username"><br>
    <p>{{nl}}</p>
    <input v-model="age"><br>
    <button v-on:click="reverseMessage">重置</button>
    <button v-on:click="addpeople">添加</button>
    <table border="1">
        <tr>
            <th>序号</th><th>名字</th><th>年龄</th><th>添加时间</th><th>操作</th>
        </tr>
        <tr  v-for="(todo,index) in todos">
            <td> {{ index+1 }}</td><td>{{ todo.name | capitalize}}</td><td>{{ todo.age }}</td><td>{{todo.time.getHours()+":"+todo.time.getMinutes()+":"+todo.time.getSeconds()}}</td><td><button v-on:click="sc(index)">删除</button></td>
        </tr>
    </table>
    <button v-on:click="scsy">删除所有</button>

</div>

</body>
</html>